package com.truckdispatching.activity;

import android.app.Activity;
import android.app.ProgressDialog;
import android.view.Gravity;
import android.view.View;
import android.widget.Toast;

public class BaseActivity extends Activity {

	private ProgressDialog mProgressDialog;

	private Toast mToast;

	public void showLoadingDialog() {
		if (mProgressDialog == null) {
			mProgressDialog = new ProgressDialog(this);
			mProgressDialog.setMessage("加载中。。。");
			mProgressDialog.setCanceledOnTouchOutside(false);
			mProgressDialog.setCancelable(true);
		}
		mProgressDialog.show();
	}

	public void dismissLoadingDialog() {
		if (mProgressDialog != null) {
			mProgressDialog.dismiss();
		}
	}

	public void showToast(final String message) {
		runOnUiThread(new Runnable() {
			@Override
			public void run() {
				if (mToast != null) {
					mToast.setText(message);
					mToast.setDuration(Toast.LENGTH_SHORT);
				} else {
					mToast = Toast.makeText(getBaseContext(), message, Toast.LENGTH_SHORT);
					mToast.setGravity(Gravity.CENTER, 0, 0);
					mToast.show();
				}
				View iView = mToast.getView();
				mToast.show();
				mToast.setView(iView);
			}
		});
	}
}
